var jsonList = {};
jsonList.state=2;
var page = 1;
var rows = 10;
$(function (){
    //获取频道列表
    $.ajax({
        url: baseNews + "/api/data/special/channel/select",
        success: function (res) {
            console.log(res);
            if (res.code == 0) {
                var obj = $(".sh_pind");

                $(res.data).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.value + "</option>");
                })
            }
        }
    })
    //获取专题id
    $.ajax({
        url: baseNews + "/api/data/article/special/select",
        success: function (res) {
            console.log(res);
            if (res.code == 0) {
                var obj = $(".zq_se");
                var obj1 = $(".atc_ztid");
                $(res.data).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.value + "</option>");
                    obj1.append("<option value='" + key.id + "'>" + key.value + "</option>");
                })
            }
        }
    })
    //获取频道列表
    $.ajax({
        url: baseNews + "/api/data/special/channel/select",
        success: function (res) {
            console.log(res);
            if (res.code == 0) {
                var obj = $(".arc_pindao");
                var obj1 = $(".arc_pd");
                $(res.data).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.value + "</option>");
                    obj1.append("<option value='" + key.id + "'>" + key.value + "</option>");
                })
            }
        }
    })
    //搜索搜索
    $(".sh_pind").change(function () {
        jsonList.cid = $(this).val();
    })
    $(".sh_ss").click(function () {
        var arc_name = $(".zt_id").val();//文章id
        var arc_sele = $(".arc_sele").val();//文章标题
        console.log(arc_sele, 333)
        if (arc_name != "") {
            jsonList.sid = arc_name
        }
        if (arc_sele != "") {
        } else {
            jsonList.title  = arc_sele;
        }
        //var atc_ztid = $(".atc_ztid").val()//专题
        page = 1;
        getList();
    })

    //审核通过
    $(".sh_wzt").on("click",function (){
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(0, ids.length - 1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要审核通过该文章吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/audit/aticle?audit=true&ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        console.log(res,333)
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('审核文章失败');
                        }
                    }
                })
            })
        }else{
            zeroModal.alert('请选择至少一条文章进行审核');
        }
    })
    //取消审核
    $(".sh_wzqx").on("click", function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(1, ids.length - 1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要审核失败该文章吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/audit/aticle?audit=false&ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        console.log(res, 333)
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('取消审核文章失败');
                        }
                    }
                })
            })
        } else {
            zeroModal.alert('请选择至少一条文章取消审核');
        }
    })
})
getList();
function getList() {
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/common/article/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".arc_list").empty();
                $(list).each(function (index, key) {
                    var state = key.state;//文章的状态
                    var state1 = key.sstate//专题的状态
                    var newState = "";//文章的
                    var newState1 = "";//专题的
                    if (state == 0) {
                        newState = "新建";
                    }
                    if (state == 1) {
                        newState = "已修改";
                    }
                    if (state == 2) {
                        newState = "待审核";
                    }
                    if (state == 3) {
                        newState = "待发布";
                    }
                    if (state == 4) {
                        newState = "已发布";
                    }
                    if (state == 10) {
                        newState = "新匹配";
                    }
                    if (state == -10) {
                        newState = "已忽略";
                    }
                    if (state == -1) {
                        newState = "审核失败";
                    }
                    if (state == -2) {
                        newState = "撤销发布";
                    }
                    //
                    
                    html += `<tr >
							<td >
								<input type="checkbox" oid="${key.id}" class="arc_isc"/>
							</td>
							<td >${key.id}</td>
							<td >${key.title}</td>
							<td >${newState}</td>
							<td >${key.sid}</td>
							<td >${key.stitle == null ? '' : key.stitle}</td>
							<td >${newState1}</td>
							<td >${key.cname == null ? '' : key.cname}</td>
							<td >${key.type?key.type:""}</td>
							<td >${key.top == true ? "是" : "否"}</td>
							<td >${key.recommend == true ? "是" : "否"}</td>
							<td >${key.diy == true ? "是" : "否"}</td>
							<td >${key.statement == true ? "有" : "无"}</td>
							<td >${key.click}</td>
							<td >${key.collect}</td>
							<td >${key.pass}</td>
							<td >${key.comment}</td>
							<td >${key.hot}</td>
							<td >${key.username?key.username:""}</td>
							<td >${key.createtime?key.createtime:""}</td>
							<td >${key.updatetime?key.updatetime:""}</td>
							<td >${key.atime?key.atime:''}</td>
							<td >${key.rtime?key.rtime:""}</td>
							<td >${key.source}</td>
							<td >${key.author}</td>
							<td >${key.stime?key.stime:''}</td>
							<td >xxx</td>
						</tr>`;
                })
                $(".arc_list").append(html);
            }
        }

    })
    //分页

}